package selfview.sufutian.com.myapplication.draw2d;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by sufutian on 2017/2/7.
 */

public class CanvasAnimiDraw extends View {

    private int mTotalWidth;
    private int mTotalHeight;
    private Paint mPaint;

    public CanvasAnimiDraw(Context context) {
        super(context);
        initPaint();
    }

    public CanvasAnimiDraw(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }

    private void initPaint() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

    public CanvasAnimiDraw(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mTotalWidth = w;
        mTotalHeight = h;
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        mPaint.setColor(Color.BLUE);
        canvas.drawRect(new RectF(0,0,mTotalWidth,mTotalHeight),mPaint);
        canvas.save();


        mPaint.setColor(Color.RED);
        canvas.drawRect(new Rect(0,0,200,200),mPaint);

        canvas.translate(100,100);
        canvas.drawRect(new Rect(0, 0, 200, 200), mPaint);

    }
}
